 <?php
class C2i_AdminController extends Zend_Controller_Action
{
	
private $admin;
	
	public function init(){
		$this->_helper->layout()->disableLayout();
		$this->_helper->layout()->setLayout("admin");
		
		
		
		 $admin=Zend_Auth::getInstance()->getIdentity();
		 $this->admin=$admin;
		 if($admin)
		 {
		 	$this->view->isauthentifier= true;
		 }else{
		 	$this->view->isauthentifier= false;
		 }
	}
		
	public function indexAction()
	{
		echo "c2i";
		
	}
  
	public function adminAction()
	{
	if ($this->_request->isPost())
	{
		$formData = $this->_request->getPost();
		$DbAdapter=Zend_Db_Table::getDefaultAdapter();
		$authAdapter = new Zend_Auth_Adapter_DbTable($DbAdapter);
		$authAdapter->setTableName('administrateur_uvt');
		$authAdapter->setIdentityColumn('login');
		$authAdapter->setCredentialColumn('password');
	
		// Set the input credential values to authenticate against
		$authAdapter->setIdentity($formData["inputEmail"]);
		$authAdapter->setCredential($formData["inputPassword"]);
		//	print_r($formData);die();
	
		// do the authentication
		$auth = Zend_Auth::getInstance();
			
		$result = $auth->authenticate($authAdapter);
	
		if ($result->isValid()) {
			// success: store database row to auth's storage
			// system. (Not the password though!)
			$data = $authAdapter->getResultRowObject(null, 'password');
			//print_r($data);die();
			$auth->getStorage()->write($data);
			// Zend_Session::setOptions(array('userid'=>$data->idpersonnes));
	
			$this->_helper->redirector("menu","menuprincipal","c2i");
		} else {
			$this->_helper->redirector("admin","admin","c2i");
			$this->view->message = 'Login failed.';
		}
	}
	}
	public function loginAction()
	{
		 
		 
		$this->view->title="Authentification";
		$this->view->authform=$auth;
	}
	
	public function logoutAction()
	{
		$this->_helper->layout()->disableLayout();
		$this->_helper->viewRenderer->setNoRender(true);
	
		$auth = Zend_Auth::getInstance();
		$auth->clearIdentity();
		$this->_helper->redirector("admin","admin","c2i");
	}
	
}
    
